<template>
    <div class="xm-login">
        <van-nav-bar title="面经登录" />
        <XmForm @onSubmit="onSubmit" btnClass="xm-login-submit" />
        <router-link class="xm-login-register" to="/register"
            >注册账号</router-link
        >
    </div>
</template>

<script>
import XmForm from '@/components/XmForm.vue'
import { LOGIN_API } from '@/constant/api'
import HttpTools from '@/utils/http'
import { USERINFO_KEY } from '@/utils/key'

export default {
  name: 'XmLogin',
  components: {
    XmForm
  },
  methods: {
    async onSubmit (form) {
      const res = await HttpTools.post(LOGIN_API, { ...form })
      window.localStorage.setItem(USERINFO_KEY, JSON.stringify(res.data))
      if (res.code === 10000) {
        this.$router.replace('/home')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.xm-login {
    .xm-login-register {
        width: 100%;
        display: inline-block;
        text-align: right;
        color: #016799;
        font-size: 12px;
        padding: 0 16px;
        box-sizing: border-box;
    }
}
</style>
